package com.mall.dubbo.api;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mall.dubbo.mapper.SmsHomeRecommendProductMapper;
import com.mall.model.domain.SmsHomeRecommendProduct;
import org.apache.commons.lang.StringUtils;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @author xyiaao
 * @description 针对表【sms_home_recommend_product(人气推荐商品表)】的数据库操作Api实现
 * @createDate 2022-03-29 19:46:09
 */
@DubboService
public class SmsHomeRecommendProductApiImpl extends ServiceImpl<SmsHomeRecommendProductMapper, SmsHomeRecommendProduct>
        implements SmsHomeRecommendProductApi {

    @Autowired
    private SmsHomeRecommendProductMapper smsHomeRecommendProductMapper;

    //分页查询推荐
    public Page<SmsHomeRecommendProduct> listPage(Integer pageNum, Integer pageSize, String productName, Integer recommendStatus) {

        LambdaQueryWrapper<SmsHomeRecommendProduct> lqw = new LambdaQueryWrapper<>();
        lqw.like(StringUtils.isNotEmpty(productName), SmsHomeRecommendProduct::getProductName, productName);
        lqw.eq(recommendStatus != null, SmsHomeRecommendProduct::getRecommendStatus, recommendStatus);
        lqw.orderByDesc(SmsHomeRecommendProduct::getSort);
        Page<SmsHomeRecommendProduct> page = new Page<>(pageNum, pageSize);

        return smsHomeRecommendProductMapper.selectPage(page, lqw);
    }

    @Override
    public List<SmsHomeRecommendProduct> findByIds(List<Long> ids, SmsHomeRecommendProduct recommendProduct) {

        LambdaQueryWrapper<SmsHomeRecommendProduct> lqw = new LambdaQueryWrapper<>();
        lqw.in(CollUtil.isNotEmpty(ids), SmsHomeRecommendProduct::getId, ids);
        lqw.eq(SmsHomeRecommendProduct::getRecommendStatus, recommendProduct.getRecommendStatus());

        return smsHomeRecommendProductMapper.selectList(lqw);
    }

    @Override
    public void updateByIds(List<Long> ids, SmsHomeRecommendProduct recommendProduct) {

        LambdaQueryWrapper<SmsHomeRecommendProduct> lqw = new LambdaQueryWrapper<>();
        lqw.in(CollUtil.isNotEmpty(ids), SmsHomeRecommendProduct::getId, ids);
        smsHomeRecommendProductMapper.update(recommendProduct, lqw);
    }

    @Override
    public void updateSort(Integer id, SmsHomeRecommendProduct recommendProduct) {

        LambdaQueryWrapper<SmsHomeRecommendProduct> lqw = new LambdaQueryWrapper<>();
        lqw.eq(id != null, SmsHomeRecommendProduct::getId, id);
        smsHomeRecommendProductMapper.update(recommendProduct, lqw);
    }

}




